/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.pima.gestrest.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

@Entity
@NamedQuery(name = Restaurant.FIND_ALL, query = "SELECT b FROM Restaurant b")
/**
 *
 * @author Mat
 */
public class Restaurant implements Serializable {
    public final static String FIND_ALL = "Restaurant.findAll";
    public final static String Del_SOM = "Restaurant.delete";

  @Id
    @GeneratedValue
    private Long id;
    @Column(nullable = false)
    private String title;
    @Column(length = 2000)
    private String adresse;
    private String chef;
    private String description;
    @OneToOne
    private Ville ville;
    @OneToOne
    private Cadre cadre;
    @OneToOne
    private Prix prix;
    @OneToOne
    private Cuisine cuisine;
    @Transient
    private Boolean selected;

    // ======================================
    // =            Constructors            =
    // ======================================
    public Restaurant() {
    }

    public Restaurant(String title, String adresse, String chef, String description, Ville ville, Cadre cadre, Prix prix, Cuisine cuisine) {

        this.title = title;
        this.adresse = adresse;
        this.chef = chef;
        this.description = description;
        this.ville = ville;
        this.cadre = cadre;
        this.prix = prix;
        this.cuisine = cuisine;
    }

    //=======================================
    //=             Getters & Setters       =
    //=======================================

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public Cadre getCadre() {
        return cadre;
    }

    public void setCadre(Cadre cadre) {
        this.cadre = cadre;
    }

    public String getChef() {
        return chef;
    }

    public void setChef(String chef) {
        this.chef = chef;
    }

    public Cuisine getCuisine() {
        return cuisine;
    }

    public void setCuisine(Cuisine cuisine) {
        this.cuisine = cuisine;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Prix getPrix() {
        return prix;
    }

    public void setPrix(Prix prix) {
        this.prix = prix;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        System.out.println("setTitle :"+title);
        this.title = title;
    }

    public Ville getVille() {
        return ville;
    }

    public void setVille(Ville ville) {
        this.ville = ville;
    }

    public Boolean isSelected() {
        return selected;
    }

    // ======================================
    // =         hash, equals, toString     =
    // ======================================

        @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Restaurant");
        sb.append("{id=").append(id);
        sb.append(", title='").append(title).append('\'');
        sb.append(", adresse='").append(adresse).append('\'');
        sb.append(", chef='").append(chef).append('\'');
        sb.append(", cadre=").append(cadre).append('\'');
        sb.append(", ville=").append(ville).append('\'');
        sb.append(", cuisine=").append(cuisine).append('\'');
        sb.append(", prix=").append(prix).append('\'');
        sb.append(", description=").append(description).append('\'');

        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
       if(((Restaurant)obj).getTitle().equals(title) && ((Restaurant)obj).getId().equals(id))
            return true;
        else
            return false;
    }
}
